//
//  SSGoodsListController.m
//  textDemo
//
//  Created by Esther on 2017/2/21.
//  Copyright © 2017年 Esther. All rights reserved.
//

#import "SSGoodsListController.h"
#import "SSGoodsListTopButtonView.h"
#import "SSGoodsListCollectionView.h"


@interface SSGoodsListController ()
@property(nonatomic, strong) SSGoodsListTopButtonView *goodsListTopButtonView;

@property(nonatomic, strong) SSGoodsListCollectionView *goodsListCollectionView;
@end

@implementation SSGoodsListController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self loadData];
    
    [self.view addSubview:self.goodsListTopButtonView];
    
    [self.view addSubview:self.goodsListCollectionView];
    
    
}


#pragma mark -
#pragma mark - 请求数据

- (void)loadData{
    [SSPromotion loadPromotionData:^(NSArray<SSPromotion *> *data) {
        self.goodsListCollectionView.promotionList = data;
        
       
    }];
}

#pragma mark -
#pragma mark - 懒加载
- (SSGoodsListTopButtonView *)goodsListTopButtonView{
    if (!_goodsListTopButtonView) {
        _goodsListTopButtonView = [[SSGoodsListTopButtonView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen ss_screenWidth], 30)];
        
    }
    return _goodsListTopButtonView;
}


- (SSGoodsListCollectionView *)goodsListCollectionView{
    if (!_goodsListCollectionView) {
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
        NSInteger itemWidth = ([UIScreen ss_screenWidth] - 10) / 2;
        
        flowLayout.itemSize = CGSizeMake(itemWidth, itemWidth / 0.725);
        
        flowLayout.minimumLineSpacing = 10;
        flowLayout.minimumInteritemSpacing = 0;
        
        _goodsListCollectionView = [[SSGoodsListCollectionView alloc] initWithFrame:CGRectMake(0, 32, [UIScreen ss_screenWidth], [UIScreen ss_screenHeight] - 32) collectionViewLayout:flowLayout];
        _goodsListCollectionView.backgroundColor = [UIColor ss_colorWithRed:242 green:242 blue:242];
//        _goodsListCollectionView.promotionList = self.promotionList;
        
        
    }
    return _goodsListCollectionView;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
